$(document).ready(function() {
	
	
	asyncCallService("/service/user/mobilebind/mobile/mobileinses", "post", "json", '', 
			function(result){}, function(){});
		
	$("#mobileVCodeBtn").data("active",true);
	$("#mobileVCodeBtn").click(function(){
		if($(this).data("active") == true){
			startTimer();
			var data = {language : i18n.lang,pwdType : "orderover"};
			syncCallService("/service/user/resetpwd/mobileresetpwd/verifycode", "post", "json", data, function(data){
			}, function(data){});
		}
	});
	
	$("#nextBtn").click(function(){
		var verifyCode=$("#mobile_vCode").val();
		if(""==verifyCode) {
			var objtip = $("#checkTip");
			objtip.addClass("Validform_wrong");
			objtip.text(i18n.register_verify_code_null);
			return;
		}
		var data = {verifyCode : verifyCode};
		syncCallService("/service/user/resetpwd/mobileresetpwd/mobilecode", "get", "json", data, function(data){
			if("error" == data) {
				var objtip = $("#checkTip");
				objtip.addClass("Validform_wrong");
				objtip.text(i18n.register_verify_code_wrong);
				return;
			} else if("timeout" == data) {
				var objtip = $("#checkTip");
				objtip.addClass("Validform_wrong");
				objtip.text(i18n.register_verify_code_timeout);
				return;
			}else if("verifyCodeCount" == data){
				var objtip = $("#checkTip");
				objtip.addClass("Validform_wrong");
				objtip.text(i18n.register_verify_code_error_count);
				return;
			}else {
				var params = {
						whiteName:$("#s_mobile").val(),
						type:'MOBILE'
				};
				syncCallService("/service/order/orderWhite/save", "post", "json", params, function(data){
					if(orderValidateWindow != undefined){
						orderValidateWindow.close();
						sfAlert('手机已验证成功');
					}
				}, function(data){});
			}
		}, function(data){});
	});
	
});

/**timer start**/

var initSec = 90;
var timer;
var sec;
function setTimer(){
	sec--;
	if (sec < 0) {
		stopTimer();
		$("#mobileVCodeBtn").removeClass("btn-resets").addClass("btn-submits");
		$("#mobileVCodeBtn").find("span").text(i18n.register_verify_code_get);
		$("#mobileVCodeBtn").css({ "cursor": "hand" });
		$("#mobileVCodeBtn").data("active",true);
	} else {
		$("#mobileVCodeBtn").find("span").text(i18n.register_verify_code_enter_resend_prefix+sec + i18n.register_verify_code_enter_resend_suffix);
	}
}

function startTimer(){
	sec = initSec;
	$("#mobileVCodeBtn").data("active",false);
	$("#mobileVCodeBtn").removeClass("btn-submits").addClass("btn-resets");
	$("#mobileVCodeBtn").find("span").text(i18n.register_verify_code_enter_resend_prefix+sec + i18n.register_verify_code_enter_resend_suffix);
	timer = window.setInterval("setTimer()", 1000);
}

function stopTimer(){
	window.clearInterval(timer);
}

/**timer end**/
